package com.xy.tianyu.module.novel.adapter

import android.view.View
import android.widget.LinearLayout
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.SizeUtils
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.xy.tianyu.R
import com.xy.tianyu.module.novel.bean.X
import com.xy.tianyu.utils.DoubleUtils
import com.xy.tianyu.utils.GlideUtils
import kotlinx.android.synthetic.main.item_competitive_recommend_child_hor.view.*

/**
 * @time 2020/11/27 10:06
 * @class 描述:
 */
class CompetitiveRecommendChildHorAdapter (layoutResId: Int,data:MutableList<X>?):
    BaseQuickAdapter<X, BaseViewHolder>(layoutResId,data) {
    override fun convert(holder: BaseViewHolder, item: X) {

        with(holder.itemView) {
            val layoutParams = iv_novel_cover_hor.layoutParams
            layoutParams.width = (ScreenUtils.getScreenWidth() - SizeUtils.dp2px(30f)) / 4
            layoutParams.height = LinearLayout.LayoutParams.WRAP_CONTENT
            iv_novel_cover_hor.layoutParams = layoutParams
            Glide.with(context).load(item.cover).apply(GlideUtils.getRequestOptions())
                .into(iv_novel_cover_hor)
            tv_novel_title_hor.text = item.newBookName
            val renqi = (item.popularity)?.toDouble()
            val renqiDb = DoubleUtils.formatDoubleOne(renqi!!.div(10000))
            tv_novel_renqi.text = context.getString(R.string.ty_book_renqi, renqiDb.toString())
        }

    }
}